package com.study.niuke;

import java.util.*;

public class Solution_NC112 {
    private static final Map<Integer, String> map = new HashMap<>();

    static {
        map.put(10, "A");
        map.put(11, "B");
        map.put(12, "C");
        map.put(13, "D");
        map.put(14, "E");
        map.put(15, "F");
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * <p>
     * 进制转换
     *
     * @param M int整型 给定整数
     * @param N int整型 转换到的进制
     * @return string字符串
     */
    public static String solve(int M, int N) {
        // write code here
        List<String> numbers = new ArrayList<>();
        int mod;
        boolean f = M > 0;
        String number;
        if (M < 0) {
            M = -M;
        }
        while (M > 0) {
            mod = M % N;
            number = String.valueOf(mod);
            if (mod > 9) {
                number = map.get(mod);
            }
            numbers.add(String.valueOf(number));
            M /= N;
        }
        Collections.reverse(numbers);
        return (!f ? "-" : "") + String.join("", numbers);
    }

    public static void main(String[] args) {
        String solve = solve(7, 2);
        System.out.println("solve = " + solve);
    }
}
